package util;

/**
 * @author tg.si@188.com
 * @todo
 * @since 2025/3/26 13:50
 */

import lombok.*;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Pagination {
    //每页的对象(元组)数
    private int pageSize = 5;
    //页号
    private int pageNo = 1;
    //对象(元组)总数
    private int totalNum = 1;
    public String toLimitClause(int totalNum) {
        this.totalNum = totalNum;
        int offset = (this.pageNo-1) * this.pageSize;
        return "limit " + offset + "," + this.pageSize;
    }

    public Pagination(int pageSize, int pageNo) {
        if (pageSize >0) {
            this.pageSize = pageSize;
        }
        if (pageNo > 0) {
            this.pageNo = pageNo;
        }
    }

    public int getPageNo() {
        return pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }
    public int getTotalNum() {
        return totalNum;
    }
}
